package com.guo.worktool.Controller;

import com.guo.worktool.common.comps.RedisUtil;
import com.guo.worktool.common.core.AjaxResult;
import com.guo.worktool.manager.AsyncManager;
import com.guo.worktool.manager.factory.AsyncFactory;
import com.guo.worktool.utils.ServletUtils;
import com.guo.worktool.utils.ip.IpUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.*;

/**
 * @Author Ronghao.Guo
 * @Date 2023/3/14 21:34
 *
 * 测试需要
 */
@RestController
@Slf4j
public class HelloController {
    @Autowired
    private RedisUtil redisUtil;

    @GetMapping("/test")
    public AjaxResult test(){
        log.info("开始访问");
        //获取客户访问ip
        final String ipaddr = IpUtils.getIpAddr(ServletUtils.getRequest());
        AsyncManager.me().execute(() -> AsyncFactory.getVisitorRecords(redisUtil, ipaddr));
        log.info("结束访问");
        return AjaxResult.error("造轮子是个技术活，你超出了轮子的范围！");
    }


    @GetMapping("/hello")
    public AjaxResult hello(){
        log.info("Hello成功访问");
        return AjaxResult.error("Hello");
    }


}
